package cn.jbt.api.admin.entity.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ModifyPassDTO {

    @Pattern(regexp = "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9])(.{8,16})$", message = "当前密码必须8-16位，并且包含字母、数字、特殊字符")
    @NotBlank(message = "当前密码不能为空")
    private String currentPass;

    @Pattern(regexp = "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9])(.{8,16})$", message = "新的密码必须8-16位，并且包含字母、数字、特殊字符")
    @NotBlank(message = "新的密码不能为空")
    private String newPass;

    @Pattern(regexp = "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9])(.{8,16})$", message = "确认密码必须8-16位，并且包含字母、数字、特殊字符")
    @NotBlank(message = "确认密码不能为空")
    private String confirmPass;

    public void validate() {

        if (!newPass.equals(confirmPass)) {
            throw new RuntimeException("新的密码和确认密码不一致");
        }

        if (currentPass.equals(newPass)) {
            throw new RuntimeException("当前密码和新的密码必须不相同");
        }
    }

}
